﻿using System;
using System.Globalization;

namespace Alex.Library.Log
{
    /// <summary>
    /// DateTime扩展类
    /// </summary>
    public static class DateTimeExtend
    {
        /// <summary>
        /// 获取DateTime是一年中的第几个星期
        /// </summary>
        /// <param name="dt"></param>
        /// <returns></returns>
        public static int WeekOfYear(this DateTime dt)
        {
            CultureInfo ci = new CultureInfo("zh-CN");
            System.Globalization.Calendar cal = ci.Calendar;
            CalendarWeekRule cwr = ci.DateTimeFormat.CalendarWeekRule;
            DayOfWeek dow = DayOfWeek.Monday;
            int week = cal.GetWeekOfYear(dt, cwr, dow);
            return week;
        }
    }
}
